﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CustomerArchives_CustomerTypeDetail : System.Web.UI.Page
{
    private string Code
    {
        get
        {
            return Request.QueryString["code"] != null ? Request.QueryString["code"].ToString() : "0";
        }
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200500105");
        if (!IsPostBack)
        {
            Bind();
        }

    }

    private void Bind()
    {
        Model.CustomerType customerType = new BLL.CustomerType().GetModel(Convert.ToInt32(this.Code));
        if (customerType != null)
        {
            lblCustomerTypeCode.Text = customerType.CT_CODE;
            txtCustomerTypeName.Text = customerType.CT_Name;
            if (customerType.ISCunKuan == 1)
            {
                rdoYes.Checked = true;
            }
            else if (customerType.ISCunKuan == 0)
            {
                rdoNo.Checked = true;
            }
            
            txtCautionMoneyLowerLimit.Text = customerType.CT_LowerLevel.ToString();
            txtDiscount.Text = customerType.CT_Discount.ToString();
            if (customerType.CT_ISDel == 1)
            {
                rdoStopYes.Checked = true;
            }
            else if (customerType.CT_ISDel == 0)
            {
                rdoStopNo.Checked = true;
            }
        }
        else
        {
            Response.Write("<script>alert('系统无法获取到该会员类型的信息！');window.location.href='CustomerType.aspx'</script>");
        }
        
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (!Check.CheckPermission("200500105", "00002"))
            {
                Share.Alert(Page, "无权操作"); return;
            }
            Model.CustomerType customerType = new BLL.CustomerType().GetModel(Convert.ToInt32(this.Code));
            if (customerType != null)
            {
                customerType.CT_Name = txtCustomerTypeName.Text;
                customerType.ISCunKuan = rdoYes.Checked ? 1 : 0;
                customerType.CT_Discount = Convert.ToDecimal(txtDiscount.Text.Trim());
                customerType.CT_LowerLevel = Convert.ToDecimal(txtCautionMoneyLowerLimit.Text);
                customerType.CT_ISDel = rdoStopYes.Checked ? 1 : 0;

                if (new BLL.CustomerType().Update(customerType))
                {
                    Share.InsertLog("200500105", "00002");
                    //Share.Alert(this.Page, "保存成功");
                    Response.Write("<script>alert('保存成功！');window.location.href='CustomerType.aspx'</script>");
                }
                else
                {
                    Share.Alert(this.Page, "保存失败");
                }
            }
            else
            {
                Response.Write("<script>alert('系统无法获取到该会员类型的信息,保存失败！');window.location.href='CustomerType.aspx'</script>");
            }
        }
        catch (FormatException ex)
        {
            Share.Alert(this.Page, "您输入的数字有误，请重新输入！");
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {

    }
}
